package com.jk1.bianligou.blg.controller;

import com.jk1.bianligou.blg.common.BaseResponse;
import com.jk1.bianligou.blg.domain.dto.cart.AmountChange;
import com.jk1.bianligou.blg.domain.vo.CartVO;
import com.jk1.bianligou.blg.service.CartService;
import com.jk1.bianligou.blg.utils.ResultUtils;
import com.jk1.bianligou.blg.utils.UserUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author WHH
 */
@RestController
@RequestMapping("/cart")
public class CartController {

    @Resource
    private CartService cartService;

    @GetMapping()
    @ApiOperation("获取用户的购物车")
    public BaseResponse<List<CartVO>> getCart(HttpServletRequest httpServletRequest) {
        //未登录逻辑...
        return ResultUtils.success(cartService.getCartById(UserUtils.getLoginUserId(httpServletRequest)));
    }

    @PostMapping("/decrease")
    @ApiOperation("减少用户购物车的库存")
    public BaseResponse<Boolean> decreaseCart(@RequestBody AmountChange amountChange, HttpServletRequest httpServletRequest) {
        //未登录逻辑...
        return ResultUtils.success(cartService.decreaseCart(amountChange, UserUtils.getLoginUserId(httpServletRequest)));
    }
    @PostMapping("/increase")
    @ApiOperation("增加用户购物车的库存")
    public BaseResponse<Boolean> increaseCart(@RequestBody AmountChange amountChange, HttpServletRequest httpServletRequest) {
        //未登录逻辑...
        return ResultUtils.success(cartService.increaseCart(amountChange, UserUtils.getLoginUserId(httpServletRequest)));
    }

    


}
